package io.gitee.mingbaobaba.apijson.querycondition.query.dao.support;

import io.gitee.mingbaobaba.apijson.querycondition.query.properties.ApiJsonQueryProperties;
import okhttp3.OkHttpClient;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * <p>OkHttpClient 工厂</p>
 */
public final class OkHttpClientFactory {

    private OkHttpClientFactory() {
    }

    public static OkHttpClient create(ApiJsonQueryProperties properties) {
        Objects.requireNonNull(properties, "ApiJsonQueryProperties不能为空");
        return new OkHttpClient.Builder()
                .connectTimeout(properties.getConnectTimeout().toMillis(), TimeUnit.MILLISECONDS)
                .readTimeout(properties.getReadTimeout().toMillis(), TimeUnit.MILLISECONDS)
                .writeTimeout(properties.getWriteTimeout().toMillis(), TimeUnit.MILLISECONDS)
                .build();
    }
}

